# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=webhook
pkgver=2.8.1
pkgrel=1
pkgdesc="A lightweight incoming webhook server to run shell commands"
arch=('loong64' 'x86_64')
url="https://github.com/adnanh/webhook"
license=('MIT')
depends=('glibc')
makedepends=('go' 'git')
source=("$pkgname-$pkgver.tar.gz::https://github.com/adnanh/webhook/archive/$pkgver.tar.gz"
        webhook.service)
sha512sums=('25edff21725ba9ac8823dbe5728234f7cd9218027e87df3e2482ef365a7dd0efe8659800233753c275f858ff87f848ff6141d09be3e0b66ff88b795680b9b635'
            '2f8c46354777050a07001156e3e94821fce43a491712e88b8930a5081060506b0b8de8d05c9ac057aa2891ff73ef855772373299006edbc62b1734af529a2014')

prepare() {
  cd webhook-$pkgver

  mkdir -p .gopath/src/github.com/adnanh
  ln -sf "$PWD" .gopath/src/github.com/adnanh/webhook
  export GOPATH="$PWD/.gopath:/usr/share/gocode"

  rm -r vendor

  go get github.com/codegangsta/negroni github.com/gorilla/mux github.com/satori/go.uuid \
         gopkg.in/fsnotify.v1 github.com/ghodss/yaml
}

build() {
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"

  cd "$srcdir"/webhook-$pkgver
  go build -o build/webhook
}

package() {
  cd webhook-$pkgver

  install -Dm755 build/webhook "$pkgdir"/usr/bin/webhook
  install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

  install -dm755 "$pkgdir"/etc/webhook
  install -Dm644 "$srcdir"/webhook.service "$pkgdir"/usr/lib/systemd/system/webhook.service
}
